/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon
 												
Class							:				UnitTypeExistsCondition
 
Function						: 				Provides a class for holding a 
												condition that specifies whether 
												a unit exists at a particular location
****************************************************************************/

package planninglanguage.softconditions;

import org.w3c.dom.DOMException;

import base.WargusGameState;
import base.WargusPlayer;
import base.WargusStateImporter;
import base.WargusUnit;


public class UnitTypeExistsSoftCondition extends SoftCondition {

	int m_playerID;
	String m_unitType;
	
	public UnitTypeExistsSoftCondition(String a_unitType, int a_playerID)
	{
		m_playerID = a_playerID;
		m_unitType = a_unitType;
	}
	public String toString(int tabs) {
		String n = super.toString(tabs);
		n = n+ "Player Id is:" + m_playerID;
		n = n + "Unit Type is" + m_unitType;
		
		return n;
	}	
	public String getUnitType()
	{
		return m_unitType;
	}
	public float test(WargusGameState a_gameState) throws NumberFormatException, DOMException
	{
		float best = 0.0f;
		
		for(WargusUnit u:a_gameState.getPlayer().getUnits()) {
			if (WargusStateImporter.unitTypeToString(u.getType()).equals(m_unitType)) {
				float tmp = ((float)(u.getHitPoints()))/((float)(WargusStateImporter.unitMaxHitPoints(u.getType())));							
				if (tmp>best) best = tmp;
			}
		}
		
		for(WargusPlayer p:a_gameState.getOpponent()) {
			for(WargusUnit u:p.getUnits()) {
				if (WargusStateImporter.unitTypeToString(u.getType()).equals(m_unitType)) {
					float tmp = ((float)(u.getHitPoints()))/((float)(WargusStateImporter.unitMaxHitPoints(u.getType())));							
					if (tmp>best) best = tmp;
				}
			}
		}
		return best;
	}
}
